﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using System.Threading;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Gift.WebApp;

public partial class backstage_category : System.Web.UI.Page
{
    // Fields
    protected BrandManager bm = new BrandManager();
    protected CategoryAdManager cam = new CategoryAdManager();
    protected CategoryBrand cb = new CategoryBrand();
    protected CategoryBrandManager cbm = new CategoryBrandManager();
    protected Category cg = new Category();
    protected CategoryManager cm = new CategoryManager();


    // Methods
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string pathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
        try
        {
            DataTable categoryById;
            HttpFileCollection files;
            ArrayList list3;
            ArrayList list4;
            CategoryAd ad;
            this.cg.CategoryName = this.txtCategoryName.Value;
            this.cg.SortOrder = Convert.ToInt32(this.txtSortOrder.Value);
            this.cg.Keywords = this.txtKeywords.Value;
            this.cg.Description = this.txtaDescription.Value;
            this.cg.IsShow = Convert.ToInt32(base.Request.Form["isShow"]);
            string str2 = base.Request.Form["brand"];
            ArrayList list = new ArrayList();
            if (str2 != null)
            {
                list = ArrayList.Adapter(str2.Split(new char[] { ',' }));
            }
            if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
            {
                this.cg.Id = base.Request.QueryString["id"];
                categoryById = this.cm.GetCategoryById(this.cg.Id);
                this.cg.ParentId = categoryById.Rows[0]["parentId"].ToString();
                this.cg.CategoryIdentity = Convert.ToInt32(categoryById.Rows[0]["categoryIdentity"]);
                if (this.cm.ModifyCategory(this.cg))
                {
                    DataTable categoryBrandByCategory = this.cbm.GetCategoryBrandByCategory(this.cg.CategoryIdentity);
                    ArrayList list2 = new ArrayList();
                    foreach (DataRow row in categoryBrandByCategory.Rows)
                    {
                        list2.Add(row["brand"].ToString());
                        if (!list.Contains(row["brand"].ToString()))
                        {
                            this.cbm.DeleteCategoryBrand(Convert.ToInt32(row["id"]));
                        }
                    }
                    foreach (string str3 in list)
                    {
                        if (!list2.Contains(str3))
                        {
                            this.cb.Category = this.cg.CategoryIdentity;
                            this.cb.Brand = Convert.ToInt32(str3);
                            this.cbm.AddCategoryBrand(this.cb);
                        }
                    }
                    files = HttpContext.Current.Request.Files;
                    if (files.Count == 8)
                    {
                        list3 = ArrayList.Adapter(base.Request.Form["categoryAdAlt"].Split(new char[] { ',' }));
                        list4 = ArrayList.Adapter(base.Request.Form["categoryAdUrl"].Split(new char[] { ',' }));
                        DataTable categoryAdByCategory = this.cam.GetCategoryAdByCategory(base.Request.QueryString["id"]);
                        ad = new CategoryAd();
                        ad.SlidesLeftAlt = list3[0].ToString();
                        ad.SlidesLeftUrl = list4[0].ToString();
                        ad.SlidesOneAlt = list3[1].ToString();
                        ad.SlidesOneUrl = list4[1].ToString();
                        ad.SlidesTwoAlt = list3[2].ToString();
                        ad.SlidesTwoUrl = list4[2].ToString();
                        ad.CategoryOneAlt = list3[3].ToString();
                        ad.CategoryOneUrl = list4[3].ToString();
                        ad.CategoryTwoAlt = list3[4].ToString();
                        ad.CategoryTwoUrl = list4[4].ToString();
                        ad.CategoryThreeAlt = list3[5].ToString();
                        ad.CategoryThreeUrl = list4[5].ToString();
                        ad.CategoryFourAlt = list3[6].ToString();
                        ad.CategoryFourUrl = list4[6].ToString();
                        ad.MiddleAlt = list3[7].ToString();
                        ad.MiddleUrl = list4[7].ToString();
                        if (categoryAdByCategory.Rows.Count > 0)
                        {
                            ad.Id = Convert.ToInt32(categoryAdByCategory.Rows[0]["id"]);
                            if (this.cam.ModifyCategoryAd(ad))
                            {
                                if (files[0].FileName != "")
                                {
                                    files[0].SaveAs(base.Server.MapPath(categoryAdByCategory.Rows[0]["slidesLeft"].ToString()));
                                }
                                if (files[1].FileName != "")
                                {
                                    files[1].SaveAs(base.Server.MapPath(categoryAdByCategory.Rows[0]["slidesOne"].ToString()));
                                }
                                if (files[2].FileName != "")
                                {
                                    files[2].SaveAs(base.Server.MapPath(categoryAdByCategory.Rows[0]["slidesTwo"].ToString()));
                                }
                                if (files[3].FileName != "")
                                {
                                    files[3].SaveAs(base.Server.MapPath(categoryAdByCategory.Rows[0]["categoryOne"].ToString()));
                                }
                                if (files[4].FileName != "")
                                {
                                    files[4].SaveAs(base.Server.MapPath(categoryAdByCategory.Rows[0]["categoryTwo"].ToString()));
                                }
                                if (files[5].FileName != "")
                                {
                                    files[5].SaveAs(base.Server.MapPath(categoryAdByCategory.Rows[0]["categoryThree"].ToString()));
                                }
                                if (files[6].FileName != "")
                                {
                                    files[6].SaveAs(base.Server.MapPath(categoryAdByCategory.Rows[0]["categoryFour"].ToString()));
                                }
                                if (files[7].FileName != "")
                                {
                                    files[7].SaveAs(base.Server.MapPath(categoryAdByCategory.Rows[0]["middle"].ToString()));
                                }
                            }
                        }
                        else
                        {
                            ad.Category = base.Request.QueryString["id"];
                            if (files[0].FileName != "")
                            {
                                ad.SlidesLeft = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[0].FileName);
                                Thread.Sleep(50);
                            }
                            else
                            {
                                ad.SlidesLeft = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                                File.Copy(base.Server.MapPath("/cn/category_ad/ChannelSlidesLeft.jpg"), base.Server.MapPath(ad.SlidesLeft), true);
                                Thread.Sleep(50);
                            }
                            if (files[1].FileName != "")
                            {
                                ad.SlidesOne = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[1].FileName);
                                Thread.Sleep(50);
                            }
                            else
                            {
                                ad.SlidesOne = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                                File.Copy(base.Server.MapPath("/cn/category_ad/ChannelSlides1.jpg"), base.Server.MapPath(ad.SlidesOne), true);
                                Thread.Sleep(50);
                            }
                            if (files[2].FileName != "")
                            {
                                ad.SlidesTwo = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[2].FileName);
                                Thread.Sleep(50);
                            }
                            else
                            {
                                ad.SlidesTwo = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                                File.Copy(base.Server.MapPath("/cn/category_ad/ChannelSlides2.jpg"), base.Server.MapPath(ad.SlidesTwo), true);
                                Thread.Sleep(50);
                            }
                            if (files[3].FileName != "")
                            {
                                ad.CategoryOne = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[3].FileName);
                                Thread.Sleep(50);
                            }
                            else
                            {
                                ad.CategoryOne = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                                File.Copy(base.Server.MapPath("/cn/category_ad/ChannelCategory1.jpg"), base.Server.MapPath(ad.CategoryOne), true);
                                Thread.Sleep(50);
                            }
                            if (files[4].FileName != "")
                            {
                                ad.CategoryTwo = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[4].FileName);
                                Thread.Sleep(50);
                            }
                            else
                            {
                                ad.CategoryTwo = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                                File.Copy(base.Server.MapPath("/cn/category_ad/ChannelCategory2.jpg"), base.Server.MapPath(ad.CategoryTwo), true);
                                Thread.Sleep(50);
                            }
                            if (files[5].FileName != "")
                            {
                                ad.CategoryThree = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[5].FileName);
                                Thread.Sleep(50);
                            }
                            else
                            {
                                ad.CategoryThree = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                                File.Copy(base.Server.MapPath("/cn/category_ad/ChannelCategory3.jpg"), base.Server.MapPath(ad.CategoryThree), true);
                                Thread.Sleep(50);
                            }
                            if (files[6].FileName != "")
                            {
                                ad.CategoryFour = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[6].FileName);
                                Thread.Sleep(50);
                            }
                            else
                            {
                                ad.CategoryFour = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                                File.Copy(base.Server.MapPath("/cn/category_ad/ChannelCategory4.jpg"), base.Server.MapPath(ad.CategoryFour), true);
                                Thread.Sleep(50);
                            }
                            if (files[7].FileName != "")
                            {
                                ad.Middle = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[7].FileName);
                                Thread.Sleep(50);
                            }
                            else
                            {
                                ad.Middle = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                                File.Copy(base.Server.MapPath("/cn/category_ad/ChannelMiddle.jpg"), base.Server.MapPath(ad.Middle), true);
                                Thread.Sleep(50);
                            }
                            if (this.cam.AddCategoryAd(ad))
                            {
                                if (files[0].FileName != "")
                                {
                                    files[0].SaveAs(base.Server.MapPath(ad.SlidesLeft));
                                }
                                if (files[1].FileName != "")
                                {
                                    files[1].SaveAs(base.Server.MapPath(ad.SlidesOne));
                                }
                                if (files[2].FileName != "")
                                {
                                    files[2].SaveAs(base.Server.MapPath(ad.SlidesTwo));
                                }
                                if (files[3].FileName != "")
                                {
                                    files[3].SaveAs(base.Server.MapPath(ad.CategoryOne));
                                }
                                if (files[4].FileName != "")
                                {
                                    files[4].SaveAs(base.Server.MapPath(ad.CategoryTwo));
                                }
                                if (files[5].FileName != "")
                                {
                                    files[5].SaveAs(base.Server.MapPath(ad.CategoryThree));
                                }
                                if (files[6].FileName != "")
                                {
                                    files[6].SaveAs(base.Server.MapPath(ad.CategoryFour));
                                }
                                if (files[7].FileName != "")
                                {
                                    files[7].SaveAs(base.Server.MapPath(ad.Middle));
                                }
                            }
                        }
                    }
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");location.href=\"category_list.aspx?pid=" + this.cg.ParentId + "\";</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
                }
            }
            else if ((base.Request.QueryString["ot"] == "ad") && (base.Request.QueryString["pid"] != null))
            {
                this.cg.Id = Guid.NewGuid().ToString();
                this.cg.ParentId = base.Request.QueryString["pid"];
                this.cg.LanguageVersion = this.Session["language_version"].ToString();
                this.cg.CategoryIdentity = this.cm.AddCategory(this.cg);
                if (this.cg.CategoryIdentity != 0)
                {
                    foreach (string str3 in list)
                    {
                        this.cb.Category = this.cg.CategoryIdentity;
                        this.cb.Brand = Convert.ToInt32(str3);
                        this.cbm.AddCategoryBrand(this.cb);
                    }
                    files = HttpContext.Current.Request.Files;
                    if (files.Count == 8)
                    {
                        list3 = ArrayList.Adapter(base.Request.Form["categoryAdAlt"].Split(new char[] { ',' }));
                        list4 = ArrayList.Adapter(base.Request.Form["categoryAdUrl"].Split(new char[] { ',' }));
                        categoryById = this.cm.GetCategoryByCategoryIdentity(this.cg.CategoryIdentity);
                        ad = new CategoryAd();
                        ad.Category = categoryById.Rows[0]["id"].ToString();
                        ad.SlidesLeftAlt = list3[0].ToString();
                        ad.SlidesLeftUrl = list4[0].ToString();
                        ad.SlidesOneAlt = list3[1].ToString();
                        ad.SlidesOneUrl = list4[1].ToString();
                        ad.SlidesTwoAlt = list3[2].ToString();
                        ad.SlidesTwoUrl = list4[2].ToString();
                        ad.CategoryOneAlt = list3[3].ToString();
                        ad.CategoryOneUrl = list4[3].ToString();
                        ad.CategoryTwoAlt = list3[4].ToString();
                        ad.CategoryTwoUrl = list4[4].ToString();
                        ad.CategoryThreeAlt = list3[5].ToString();
                        ad.CategoryThreeUrl = list4[5].ToString();
                        ad.CategoryFourAlt = list3[6].ToString();
                        ad.CategoryFourUrl = list4[6].ToString();
                        ad.MiddleAlt = list3[7].ToString();
                        ad.MiddleUrl = list4[7].ToString();
                        if (files[0].FileName != "")
                        {
                            ad.SlidesLeft = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[0].FileName);
                            Thread.Sleep(50);
                        }
                        else
                        {
                            ad.SlidesLeft = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            File.Copy(base.Server.MapPath("/cn/category_ad/ChannelSlidesLeft.jpg"), base.Server.MapPath(ad.SlidesLeft), true);
                            Thread.Sleep(50);
                        }
                        if (files[1].FileName != "")
                        {
                            ad.SlidesOne = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[1].FileName);
                            Thread.Sleep(50);
                        }
                        else
                        {
                            ad.SlidesOne = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            File.Copy(base.Server.MapPath("/cn/category_ad/ChannelSlides1.jpg"), base.Server.MapPath(ad.SlidesOne), true);
                            Thread.Sleep(50);
                        }
                        if (files[2].FileName != "")
                        {
                            ad.SlidesTwo = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[2].FileName);
                            Thread.Sleep(50);
                        }
                        else
                        {
                            ad.SlidesTwo = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            File.Copy(base.Server.MapPath("/cn/category_ad/ChannelSlides2.jpg"), base.Server.MapPath(ad.SlidesTwo), true);
                            Thread.Sleep(50);
                        }
                        if (files[3].FileName != "")
                        {
                            ad.CategoryOne = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[3].FileName);
                            Thread.Sleep(50);
                        }
                        else
                        {
                            ad.CategoryOne = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            File.Copy(base.Server.MapPath("/cn/category_ad/ChannelCategory1.jpg"), base.Server.MapPath(ad.CategoryOne), true);
                            Thread.Sleep(50);
                        }
                        if (files[4].FileName != "")
                        {
                            ad.CategoryTwo = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[4].FileName);
                            Thread.Sleep(50);
                        }
                        else
                        {
                            ad.CategoryTwo = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            File.Copy(base.Server.MapPath("/cn/category_ad/ChannelCategory2.jpg"), base.Server.MapPath(ad.CategoryTwo), true);
                            Thread.Sleep(50);
                        }
                        if (files[5].FileName != "")
                        {
                            ad.CategoryThree = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[5].FileName);
                            Thread.Sleep(50);
                        }
                        else
                        {
                            ad.CategoryThree = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            File.Copy(base.Server.MapPath("/cn/category_ad/ChannelCategory3.jpg"), base.Server.MapPath(ad.CategoryThree), true);
                            Thread.Sleep(50);
                        }
                        if (files[6].FileName != "")
                        {
                            ad.CategoryFour = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[6].FileName);
                            Thread.Sleep(50);
                        }
                        else
                        {
                            ad.CategoryFour = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            File.Copy(base.Server.MapPath("/cn/category_ad/ChannelCategory4.jpg"), base.Server.MapPath(ad.CategoryFour), true);
                            Thread.Sleep(50);
                        }
                        if (files[7].FileName != "")
                        {
                            ad.Middle = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + Path.GetExtension(files[7].FileName);
                            Thread.Sleep(50);
                        }
                        else
                        {
                            ad.Middle = "/cn/category_ad/" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + ".jpg";
                            File.Copy(base.Server.MapPath("/cn/category_ad/ChannelMiddle.jpg"), base.Server.MapPath(ad.Middle), true);
                            Thread.Sleep(50);
                        }
                        if (this.cam.AddCategoryAd(ad))
                        {
                            if (files[0].FileName != "")
                            {
                                files[0].SaveAs(base.Server.MapPath(ad.SlidesLeft));
                            }
                            if (files[1].FileName != "")
                            {
                                files[1].SaveAs(base.Server.MapPath(ad.SlidesOne));
                            }
                            if (files[2].FileName != "")
                            {
                                files[2].SaveAs(base.Server.MapPath(ad.SlidesTwo));
                            }
                            if (files[3].FileName != "")
                            {
                                files[3].SaveAs(base.Server.MapPath(ad.CategoryOne));
                            }
                            if (files[4].FileName != "")
                            {
                                files[4].SaveAs(base.Server.MapPath(ad.CategoryTwo));
                            }
                            if (files[5].FileName != "")
                            {
                                files[5].SaveAs(base.Server.MapPath(ad.CategoryThree));
                            }
                            if (files[6].FileName != "")
                            {
                                files[6].SaveAs(base.Server.MapPath(ad.CategoryFour));
                            }
                            if (files[7].FileName != "")
                            {
                                files[7].SaveAs(base.Server.MapPath(ad.Middle));
                            }
                        }
                    }
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加成功！\");location.href=\"category_list.aspx?pid=" + this.cg.ParentId + "\";</script>");
                }
                else
                {
                    base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
                }
            }
        }
        catch
        {
            if ((base.Request.QueryString["ot"] == "ed") && (base.Request.QueryString["id"] != null))
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
            }
            else
            {
                base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"添加失败！\");</script>");
            }
        }
    }

    protected StringBuilder CategoryAdBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if ((base.Request.QueryString["pid"] == null) || (base.Request.QueryString["ot"] == null))
            {
                return builder;
            }
            if ((base.Request.QueryString["pid"] == "00000000-0000-0000-0000-000000000000") && (base.Request.QueryString["ot"] == "ed"))
            {
                DataTable categoryAdByCategory = this.cam.GetCategoryAdByCategory(base.Request.QueryString["id"]);
                builder.AppendLine("<tr><td colspan=\"4\">分类广告</td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片左侧广告：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 186px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelSlidesLeft.jpg" : categoryAdByCategory.Rows[0]["slidesLeft"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：186*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesLeftAlt"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesLeftUrl"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片广告一：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 405px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelSlides1.jpg" : categoryAdByCategory.Rows[0]["slidesOne"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：810*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesOneAlt"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesOneUrl"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片广告二：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 405px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelSlides2.jpg" : categoryAdByCategory.Rows[0]["slidesTwo"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：810*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesTwoAlt"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["slidesTwoUrl"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告一：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 190px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelCategory1.jpg" : categoryAdByCategory.Rows[0]["categoryOne"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：380*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryOneAlt"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryOneUrl"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告二：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 190px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelCategory2.jpg" : categoryAdByCategory.Rows[0]["categoryTwo"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：380*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryTwoAlt"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryTwoUrl"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告三：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 190px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelCategory3.jpg" : categoryAdByCategory.Rows[0]["categoryThree"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：380*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryThreeAlt"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryThreeUrl"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告四：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 190px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelCategory4.jpg" : categoryAdByCategory.Rows[0]["categoryFour"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：380*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryFourAlt"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["categoryFourUrl"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">中间广告：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 380px;\" src=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "/cn/category_ad/ChannelMiddle.jpg" : categoryAdByCategory.Rows[0]["middle"].ToString()) + "\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：1000*310 分辨率：72像素 格式：jpg,bmp,gif,png<br >提示：高度可自定</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["middleAlt"].ToString()) + "\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" value=\"" + ((categoryAdByCategory.Rows.Count == 0) ? "" : categoryAdByCategory.Rows[0]["middleUrl"].ToString()) + "\" /></td></tr>");
                return builder;
            }
            if ((base.Request.QueryString["pid"] == "00000000-0000-0000-0000-000000000000") && (base.Request.QueryString["ot"] == "ad"))
            {
                builder.AppendLine("<tr><td colspan=\"4\">分类广告</td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片左侧广告：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelSlidesLeft.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：210*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片广告一：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 380px;\" src=\"/cn/category_ad/ChannelSlides1.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：790*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">幻灯片广告二：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 380px;\" src=\"/cn/category_ad/ChannelSlides2.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：790*350 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告一：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelCategory1.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：390*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告二：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelCategory2.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：390*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告三：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelCategory3.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：390*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">分类广告四：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 210px;\" src=\"/cn/category_ad/ChannelCategory4.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：390*520 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
                builder.AppendLine("<tr><td rowspan=\"3\" class=\"td_title1\">中间广告：</td><td rowspan=\"3\" class=\"td_content1\" style=\"width: 40%\"><img style=\"width: 380px;\" src=\"/cn/category_ad/ChannelMiddle.jpg\" /></td><td class=\"td_title1\">图片路径：</td><td class=\"td_content1\"><input name=\"categoryAd\" type=\"file\" class=\"file\" /><br /><span class=\"imgClass\">图片大小：1000*310 分辨率：72像素 格式：jpg,bmp,gif,png</span></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">图片描述：</td><td class=\"td_content1\"> <input name=\"categoryAdAlt\" type=\"text\" class=\"file\" maxlength=\"50\" /></td></tr>");
                builder.AppendLine("<tr><td class=\"td_title1\">链接地址：</td><td class=\"td_content1\"><input name=\"categoryAdUrl\" type=\"text\" class=\"file\" maxlength=\"200\" /></td></tr>");
            }
        }
        catch
        {
        }
        return builder;
    }

    private void CategoryBind()
    {
        try
        {
            DataTable categoryById = this.cm.GetCategoryById(base.Request.QueryString["id"]);
            if (categoryById.Rows.Count > 0)
            {
                if (categoryById.Rows[0]["parentId"].ToString() != "00000000-0000-0000-0000-000000000000")
                {
                    DataTable table2 = this.cm.GetCategoryById(categoryById.Rows[0]["parentId"].ToString());
                    if (table2.Rows.Count > 0)
                    {
                        this.lblParentCategory.InnerText = table2.Rows[0]["categoryName"].ToString();
                    }
                }
                else
                {
                    this.lblParentCategory.InnerText = "顶级分类";
                }
                this.txtCategoryName.Value = categoryById.Rows[0]["categoryName"].ToString();
                this.txtSortOrder.Value = categoryById.Rows[0]["sortOrder"].ToString();
                if (Convert.ToInt32(categoryById.Rows[0]["isShow"]) == 1)
                {
                    this.rdIsShow1.Checked = true;
                }
                else
                {
                    this.rdIsShow0.Checked = true;
                }
                this.txtKeywords.Value = categoryById.Rows[0]["keywords"].ToString();
                this.txtaDescription.Value = categoryById.Rows[0]["description"].ToString();
            }
        }
        catch
        {
        }
    }

    public StringBuilder GetBcakLocation()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (base.Request.QueryString["id"] != null)
            {
                DataTable categoryById = this.cm.GetCategoryById(base.Request.QueryString["id"]);
                if (categoryById.Rows.Count > 0)
                {
                    builder.Append("location.href='category_list.aspx?pid=" + categoryById.Rows[0]["parentId"].ToString() + "';");
                }
                return builder;
            }
            if (base.Request.QueryString["pid"] != null)
            {
                builder.Append("location.href='category_list.aspx?pid=" + base.Request.QueryString["pid"] + "';");
            }
        }
        catch
        {
        }
        return builder;
    }

    public StringBuilder GetBrand()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if (base.Request.QueryString["pid"] == null)
            {
                return builder;
            }
            DataTable brandByLanguageVersionAndParentId = this.bm.GetBrandByLanguageVersionAndParentId(this.Session["language_version"].ToString(), base.Request.QueryString["pid"]);
            DataTable categoryBrandByCategory = new DataTable();
            if (base.Request.QueryString["id"] != null)
            {
                categoryBrandByCategory = this.cbm.GetCategoryBrandByCategory(Convert.ToInt32(this.cm.GetCategoryById(base.Request.QueryString["id"]).Rows[0]["categoryIdentity"]));
            }
            if (brandByLanguageVersionAndParentId.Rows.Count <= 0)
            {
                return builder;
            }
            foreach (DataRow row in brandByLanguageVersionAndParentId.Rows)
            {
                bool flag = false;
                if (categoryBrandByCategory.Rows.Count > 0)
                {
                    foreach (DataRow row2 in categoryBrandByCategory.Rows)
                    {
                        if (Convert.ToInt32(row2["brand"]) == Convert.ToInt32(row["id"]))
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    builder.AppendLine("<input id=\"cb" + row["id"].ToString() + "\" name=\"brand\" value=\"" + row["id"].ToString() + "\" type=\"checkbox\" checked=\"checked\" />" + row["brandName"].ToString() + "");
                }
                else
                {
                    builder.AppendLine("<input id=\"cb" + row["id"].ToString() + "\" name=\"brand\" value=\"" + row["id"].ToString() + "\" type=\"checkbox\" />" + row["brandName"].ToString() + "");
                }
            }
        }
        catch
        {
        }
        return builder;
    }

    public StringBuilder GetTitle()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            if ((base.Request.QueryString["ot"] != null) && (base.Request.QueryString["id"] != null))
            {
                builder.Append("编辑分类");
                return builder;
            }
            if ((base.Request.QueryString["ot"] != null) && (base.Request.QueryString["pid"] != null))
            {
                builder.Append("添加分类");
            }
        }
        catch
        {
        }
        return builder;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
        if (!base.IsPostBack)
        {
            if ((base.Request.QueryString["ot"] != null) && (base.Request.QueryString["id"] != null))
            {
                this.CategoryBind();
            }
            else if ((base.Request.QueryString["ot"] != null) && (base.Request.QueryString["pid"] != null))
            {
                if (base.Request.QueryString["pid"] == "00000000-0000-0000-0000-000000000000")
                {
                    this.lblParentCategory.InnerText = "顶级分类";
                }
                else
                {
                    DataTable categoryById = this.cm.GetCategoryById(base.Request.QueryString["pid"]);
                    if (categoryById.Rows.Count > 0)
                    {
                        this.lblParentCategory.InnerText = categoryById.Rows[0]["categoryName"].ToString();
                    }
                }
                this.rdIsShow1.Checked = true;
            }
        }
    }

}